package com.htc.android.footprints.activity;

import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.DialogInterface.OnKeyListener;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.location.Address;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.os.RemoteException;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.ViewSwitcher;
import com.htc.android.footprints.ILocationAgentCallback;
import com.htc.android.footprints.ILocationAgentCallback.Stub;
import com.htc.android.footprints.ILocationAgentService;
import com.htc.android.footprints.ILocationAgentService.Stub;
import com.htc.android.footprints.R;
import com.htc.android.footprints.commonui.AudioRecordDialog;
import com.htc.android.footprints.commonui.AudioRecordDialog.recordStateListener;
import com.htc.android.footprints.commonui.HtcDialog;
import com.htc.android.footprints.provider.FootprintManager;
import com.htc.android.footprints.service.LocationAgentService;
import com.htc.android.footprints.utils.FootprintUtils;
import com.htc.android.footprints.utils.SettingInfo;
import com.htc.android.footprints.utils.StorageUtil;
import com.htc.android.footprints.utils.StorageUtil.OnChangeStorageListener;
import com.htc.android.footprints.utils.TitleGenerator;
import com.htc.android.footprints.utils.TitleGenerator.SearchListener;
import com.htc.android.footprints.utils.camera.FootprintImageManager;
import com.htc.android.footprints.view.PlayButton;
import com.htc.android.footprints.vo.Category;
import com.htc.android.footprints.vo.Footprint;
import com.htc.widget.HtcAlertDialog;
import com.htc.widget.HtcAlertDialog.Builder;
import java.io.File;
import java.text.DecimalFormat;
import java.util.Date;

public class PostcardActivity extends Activity implements View.OnClickListener {
	public static final String EXTRA_ADDRESS = "ADDRESS";
	public static final String EXTRA_CATEGORY = "CATEGORY";
	public static final String EXTRA_FIX_LOCATION = "FIX_LOCATION";
	public static final String EXTRA_FIX_NETWORK = "FIX_NETWORK";
	public static final String EXTRA_NOTE = "NOTE";
	public static final String EXTRA_PHONE = "PHONE";
	public static final String EXTRA_TILE_NAME = "TITLE_NAME";
	public static final String EXTRA_WEBSITE = "WEBSITE";
	private static final int FIRST_RETRIEVE_ADDRESS_DIALOG = 2;
	private static final int GPS_DISABLED_DIALOG = 1;
	private static final int HANDLE_DESTORY_ACTIVITY = 57;
	private static final int HANDLE_DISMISS_PROGRESS_DIALOG = 55;
	private static final int HANDLE_FIRST_RETRIEVE_ADDRESS = 56;
	private static final int HANDLE_GEOCODER_BY_GPS = 52;
	private static final int HANDLE_GEOCODER_BY_NET = 53;
	private static final int HANDLE_SHOW_DIALG = 50;
	private static final int HANDLE_UPDATE_INDICATOR = 54;
	private static final int HANDLE_UPDATE_TITLE = 51;
	private static final int LOCATION_PICKER_NOT_FOUND_DIALOG = 4;
	public static final int MENU_ADVANCED_EDIT = 5;
	public static final int MENU_DELETE = 4;
	public static final int MENU_FIND_ON_MAP = 1;
	public static final int MENU_REFRESH_GPS = 2;
	public static final int MENU_RE_CAPTURE = 3;
	public static final int MENU_VOICE_RECORD = 0;
	private static final int PROGRESS_DIALOG = 3;
	private static final int REQUEST_RECAPTURE = 5555;
	private static final int REQUEST_RECORD = 222;
	private static final int RESULT_LOCATION_PICKER = 1;
	private static final int SELECT_LOCATION_DIALOG = 0;
	private static final int SERVICE_BINDED = 2;
	private static final int SERVICE_BINDING = 1;
	private static final int SERVICE_UNBIND = 0;
	private static final String TAG = "PostcardActivity";
	private View buttonDone;
	private PlayButton buttonPlay;
	DialogInterface.OnKeyListener dlgKeyListener;
	private boolean gpsEnabled;
	boolean indicatorFlag;
	private boolean isLanuchByWidget = false;
	private boolean isPickerRunning = false;
	private boolean isRecaptureRunning = false;
	private int mBindState = 0;
	private ILocationAgentCallback mCallback;
	private ServiceConnection mConnection;
	private Location mFixLocation = null;
	private Location mFixNetwork = null;
	private Footprint mFootprint = null;
	private TextView mFootprintAddDate;
	private TextView mFootprintTitle;
	private TextView mGpsText;
	private final Handler mHandler;
	private ImageView mIndicator = null;
	private HtcAlertDialog mListDialog = null;
	private Menu mMenu = null;
	private ImageView mPostCardPreview;
	private Category mSelectedCategory;
	private String mSelectedCateoryStr;
	ILocationAgentService mService;
	private StorageUtil mStorageUtil;
	private boolean needAnimation;
	private ProgressDialog progressDialog;
	private String[] projection;
	private AudioRecordDialog recordDialog;
	private boolean refreshRequired = false;

	public PostcardActivity() {
		String[] arrayOfString = new String[4];
		arrayOfString[0] = "_id";
		arrayOfString[1] = "_display_name";
		arrayOfString[2] = "_data";
		arrayOfString[3] = "date_added";
		this.projection = arrayOfString;
		this.mHandler = new Handler() {
			public void handleMessage(Message paramMessage) {
				switch (paramMessage.what) {
				default:
				case 50:
				case 55:
				case 51:
				case 52:
				case 53:
				case 54:
				case 56:
				case 57:
				}
				while (true) {
					return;
					PostcardActivity.this.showDialog(0);
					continue;
					if ((PostcardActivity.this.progressDialog == null)
							|| (!PostcardActivity.this.progressDialog
									.isShowing()))
						continue;
					PostcardActivity.this.progressDialog.dismiss();
					continue;
					PostcardActivity.this.mFootprintTitle
							.setText(PostcardActivity.this.mFootprint.mName);
					continue;
					PostcardActivity.this
							.geocoderTitle(PostcardActivity.this.mFixLocation);
					continue;
					PostcardActivity.this
							.geocoderTitle(PostcardActivity.this.mFixNetwork);
					continue;
					PostcardActivity.this.updateToFootprint();
					PostcardActivity.this.updateAccuracyToIndicator();
					PostcardActivity.this.setLocationText();
					continue;
					SettingInfo localSettingInfo = SettingInfo
							.getInstance(PostcardActivity.this);
					if (!localSettingInfo.isFirstRetrieveAddress())
						continue;
					PostcardActivity.this.showDialog(2);
					localSettingInfo.setFirstRetrieveAddress(false);
					continue;
					Intent localIntent = new Intent(PostcardActivity.this,
							FootprintCamera.class);
					localIntent.putExtra("LAUNCH_BY_WIDGET",
							PostcardActivity.this.isLanuchByWidget);
					if (PostcardActivity.this.mSelectedCategory != null)
						localIntent.putExtra("CATEGORY",
								PostcardActivity.this.mSelectedCategory);
					PostcardActivity.this.startActivity(localIntent);
					PostcardActivity.this.finish();
				}
			}
		};
		this.dlgKeyListener = new DialogInterface.OnKeyListener() {
			public boolean onKey(DialogInterface paramDialogInterface,
					int paramInt, KeyEvent paramKeyEvent) {
				int i;
				if ((paramDialogInterface == PostcardActivity.this.progressDialog)
						&& (paramInt == 4)) {
					Log.i("PostcardActivity", "keyCode = KEYCODE_BACK");
					TitleGenerator.getInstance(PostcardActivity.this)
							.stopTitleSearch();
					PostcardActivity.this.progressDialog.cancel();
					i = 1;
				}
				while (true) {
					return i;
					if ((paramDialogInterface == PostcardActivity.this.mListDialog)
							&& (paramInt == 4))
						;
					try {
						if (PostcardActivity.this.gpsEnabled) {
							PostcardActivity.this.mService.continueTracking();
							PostcardActivity.this.mService
									.setTimeoutNotify(true);
						}
						i = 0;
					} catch (RemoteException localRemoteException) {
						while (true)
							localRemoteException.printStackTrace();
					}
				}
			}
		};
		this.mService = null;
		this.mConnection = new ServiceConnection() {
			public void onServiceConnected(ComponentName paramComponentName,
					IBinder paramIBinder) {
				Log.d("PostcardActivity",
						"onServiceConnected. mBindState = SERVICE_BINDED");
				PostcardActivity.this.mService = ILocationAgentService.Stub
						.asInterface(paramIBinder);
				PostcardActivity.access$1902(PostcardActivity.this, 2);
				try {
					Log.d("PostcardActivity",
							"mService.resume() at onServiceConnected");
					PostcardActivity.this.mService.resume();
					PostcardActivity.this.mService
							.registerCallback(PostcardActivity.this.mCallback);
					if (!PostcardActivity.this.mService.isTracking()) {
						if (PostcardActivity.this.refreshRequired) {
							PostcardActivity.this.mService.enableMyLocation();
							PostcardActivity.this.getWindow().addFlags(128);
							PostcardActivity.access$1602(PostcardActivity.this,
									false);
							return;
						}
						Log.d("PostcardActivity",
								"onServiceConnected call HANDLE_UPDATE_INDICATOR");
						PostcardActivity.this.mHandler.sendEmptyMessageDelayed(
								54, 500L);
					}
				} catch (RemoteException localRemoteException) {
					localRemoteException.printStackTrace();
				}
				PostcardActivity.this.mGpsText.setText(PostcardActivity.this
						.getResources().getString(2131361809));
				PostcardActivity.this.getWindow().addFlags(128);
			}

			public void onServiceDisconnected(ComponentName paramComponentName) {
				Log.w("PostcardActivity",
						"onServiceDisconnected. mBindState = SERVICE_UNBIND");
				PostcardActivity.access$1902(PostcardActivity.this, 0);
			}
		};
		this.indicatorFlag = true;
		this.mCallback = new ILocationAgentCallback.Stub() {
			public void onAgentPause() throws RemoteException {
			}

			public void onUpdateStatus(int paramInt1, int paramInt2,
					double paramDouble1, double paramDouble2)
					throws RemoteException {
				switch (paramInt1) {
				default:
				case 10:
				case 11:
				case 13:
				case 14:
				case 12:
				}
				while (true) {
					return;
					PostcardActivity.this.mIndicator.setVisibility(0);
					if (PostcardActivity.this.mFixLocation == null)
						PostcardActivity.this.mIndicator.setImageLevel(6);
					while (true) {
						Log.i("PostcardActivity",
								"onUpdateStatus : INDICATOR_STOP");
						break;
						if (PostcardActivity.this.mFootprint.mAccuracy == 2) {
							PostcardActivity.this.mIndicator.setImageLevel(5);
							continue;
						}
						if (PostcardActivity.this.mFootprint.mAccuracy != 3)
							continue;
						PostcardActivity.this.mIndicator.setImageLevel(7);
					}
					PostcardActivity.this.mGpsText
							.setText(PostcardActivity.this.getResources()
									.getString(2131361809));
					if (PostcardActivity.this.indicatorFlag)
						PostcardActivity.this.mIndicator
								.setImageLevel(paramInt2);
					for (PostcardActivity.this.indicatorFlag = false;; PostcardActivity.this.indicatorFlag = true) {
						PostcardActivity.this.mIndicator
								.setImageLevel(paramInt2);
						Log.i("PostcardActivity",
								"onUpdateStatus : INDICATOR_TRACKING");
						break;
						PostcardActivity.this.mIndicator.setImageLevel(0);
					}
					PostcardActivity.this.mIndicator.setVisibility(0);
					PostcardActivity.this.mIndicator.setImageLevel(paramInt2);
					String str1 = FootprintUtils
							.getFormatedLat((int) (1000000.0D * paramDouble1));
					String str2 = FootprintUtils
							.getFormatedLon((int) (1000000.0D * paramDouble2));
					String str3 = str1 + ", " + str2;
					PostcardActivity.this.mGpsText.setText(str3);
					if (PostcardActivity.this.mFixLocation == null)
						PostcardActivity.access$602(PostcardActivity.this,
								new Location("gps"));
					PostcardActivity.this.mFixLocation
							.setLatitude(paramDouble1);
					PostcardActivity.this.mFixLocation
							.setLongitude(paramDouble2);
					PostcardActivity.this.saveFootprint(PostcardActivity.this);
					PostcardActivity.this.updateToFootprint();
					PostcardActivity.this.mHandler.sendEmptyMessage(52);
					if (PostcardActivity.this.mListDialog != null)
						PostcardActivity.this.mListDialog.dismiss();
					PostcardActivity.this.mService.stopTrackingWithoutNotify();
					PostcardActivity.this.getWindow().clearFlags(128);
					Log.i("PostcardActivity",
							"onUpdateStatus : INDICATOR_FIX_GPS");
					continue;
					if (PostcardActivity.this.mFixNetwork == null) {
						PostcardActivity.access$802(PostcardActivity.this,
								new Location("network"));
						PostcardActivity.this.mFixNetwork
								.setLatitude(paramDouble1);
						PostcardActivity.this.mFixNetwork
								.setLongitude(paramDouble2);
						PostcardActivity.this.mHandler.sendEmptyMessageDelayed(
								53, 500L);
					}
					while (true) {
						Log.i("PostcardActivity",
								"onUpdateStatus : INDICATOR_FIX_NETWORK");
						break;
						PostcardActivity.this.mFixNetwork
								.setLatitude(paramDouble1);
						PostcardActivity.this.mFixNetwork
								.setLongitude(paramDouble2);
					}
					PostcardActivity.this.showDialog(0);
					Log.i("PostcardActivity",
							"onUpdateStatus : INDICATOR_TIMEOUT");
				}
			}
		};
	}

	private void bindLocationAgentService() {
		Log.i("PostcardActivity",
				"bind LocationAgentService. mBindState = SERVICE_BINDING");
		this.mBindState = 1;
		Intent localIntent = new Intent();
		localIntent.setClass(this, LocationAgentService.class);
		bindService(localIntent, this.mConnection, 1);
	}

	private void doFindOnMap() {
		getWindow().clearFlags(128);
		Intent localIntent = new Intent("com.htc.android.locationpicker");
		localIntent.putExtra("PickerIcon", ((BitmapDrawable) getResources()
				.getDrawable(2130837655)).getBitmap());
		localIntent.putExtra("InputLocation", 3);
		localIntent.putExtra("PickerMode", 1);
		localIntent.putExtra("PickerPanelStyle", 8);
		localIntent.putExtra("PickerReturnType", 9);
		if (this.mFixLocation == null)
			if (this.mFixNetwork != null) {
				localIntent.putExtra("PickerLatitude",
						this.mFixNetwork.getLatitude());
				localIntent.putExtra("PickerLongitude",
						this.mFixNetwork.getLongitude());
				localIntent
						.putExtra(
								"PickerAlertConnectionFailed",
								SettingInfo.getInstance(this).showConnectionFailedAlert);
			}
		while (true) {
			try {
				this.isPickerRunning = true;
				startActivityForResult(localIntent, 1);
				return;
				localIntent.putExtra("InputLocation", 4);
				break;
				localIntent.putExtra("PickerLatitude",
						this.mFixLocation.getLatitude());
				localIntent.putExtra("PickerLongitude",
						this.mFixLocation.getLongitude());
			} catch (ActivityNotFoundException localActivityNotFoundException) {
				this.mGpsText.setText(getResources().getString(2131361810));
			}
			try {
				this.mService.stopTracking();
				this.mService.setTimeoutNotify(true);
				updateToFootprint();
				updateAccuracyToIndicator();
				showDialog(4);
			} catch (RemoteException localRemoteException) {
				while (true)
					localRemoteException.printStackTrace();
			}
		}
	}

	private void geocoderTitle(Location paramLocation) {
		String str = paramLocation.getProvider();
		SettingInfo localSettingInfo = SettingInfo.getInstance(this);
		if ((str.equalsIgnoreCase("gps")) || (str.equalsIgnoreCase("map"))) {
			Log.d("PostcardActivity", "geocoderTitle by using GPS");
			if (localSettingInfo.retrieveAddress)
				showDialog(3);
		}
		while (true) {
			DecimalFormat localDecimalFormat = new DecimalFormat(" ##000");
			TitleGenerator.getInstance(this).getTitleFromNetwork(
					paramLocation,
					new TitleGenerator.SearchListener(localDecimalFormat,
							localSettingInfo) {
						public void onResult(boolean paramBoolean1,
								String paramString1, String paramString2,
								Address paramAddress, boolean paramBoolean2) {
							PostcardActivity.this.mHandler.sendEmptyMessage(55);
							if ((!paramBoolean1) || (paramString1 == null))
								return;
							int i = SettingInfo.getInstance(
									PostcardActivity.this)
									.getCurrentSerialNumber();
							PostcardActivity.this.mFootprint.mName = (paramString1 + this.val$mf
									.format(i));
							if ((paramBoolean2)
									&& (this.val$setting.retrieveAddress)) {
								Log.d("PostcardActivity",
										"onResult. fixedByGPS");
								PostcardActivity.this.mHandler
										.sendEmptyMessage(56);
								PostcardActivity.this.mFootprint.mAddr = paramString2;
								String str1 = paramAddress.getPhone();
								if (str1 != null)
									PostcardActivity.this.mFootprint.mTel = str1;
								String str2 = paramAddress.getUrl();
								if (str2 != null)
									PostcardActivity.this.mFootprint.mSite = str2;
							}
							while (true) {
								PostcardActivity.this.mHandler
										.sendEmptyMessage(51);
								break;
								Log.d("PostcardActivity",
										"onResult. NOT fixedByGPS");
							}
						}
					});
			return;
			Log.d("PostcardActivity", "geocoderTitle by using network");
		}
	}

	private void innerUnbindLocationAgentService(boolean paramBoolean) {
		try {
			if (this.mService != null) {
				Log.d("PostcardActivity", "removeCallback");
				this.mService.removeCallback(this.mCallback);
				if (paramBoolean)
					this.mService.shutdownAgent();
			}
			unbindService(this.mConnection);
			this.mService = null;
			this.mBindState = 0;
			return;
		} catch (RemoteException localRemoteException) {
			while (true)
				localRemoteException.printStackTrace();
		}
	}

	private void removeQueuedMessages() {
		this.mHandler.removeMessages(50);
		this.mHandler.removeMessages(51);
		this.mHandler.removeMessages(52);
		this.mHandler.removeMessages(53);
		this.mHandler.removeMessages(54);
		this.mHandler.removeMessages(56);
	}

	private void setLocationText() {
		if (this.mFixLocation != null) {
			double d1 = this.mFixLocation.getLatitude();
			double d2 = this.mFixLocation.getLongitude();
			String str1 = FootprintUtils
					.getFormatedLat((int) (d1 * 1000000.0D));
			String str2 = FootprintUtils
					.getFormatedLon((int) (d2 * 1000000.0D));
			String str3 = str1 + " . " + str2;
			this.mGpsText.setText(str3);
		}
	}

	private void showAnimation() {
		ViewSwitcher localViewSwitcher = (ViewSwitcher) findViewById(2131492939);
		findViewById(2131493007);
		((ImageView) findViewById(2131493006))
				.setImageBitmap(FootprintImageManager.getInstance().getImage(
						new File(this.mFootprint.mPicPath), this));
		localViewSwitcher.reset();
		localViewSwitcher.setAnimateFirstView(false);
		localViewSwitcher.setDisplayedChild(0);
		localViewSwitcher.setInAnimation(getApplicationContext(), 2130968579);
		localViewSwitcher.setOutAnimation(getApplicationContext(), 2130968589);
		new Handler().postDelayed(new Runnable(localViewSwitcher) {
			public void run() {
				this.val$switcher.showNext();
				this.val$switcher.setVisibility(0);
				PostcardActivity.access$002(PostcardActivity.this, false);
			}
		}, 10L);
	}

	private void unbindLocationAgentService(boolean paramBoolean) {
		Log.i("PostcardActivity", "unbind LocationAgentService. mBindState = "
				+ this.mBindState);
		if (this.mBindState == 1) {
			Log.d("PostcardActivity",
					"LocationAgentService is still in binding. but user call unbind");
			innerUnbindLocationAgentService(paramBoolean);
		}
		while (true) {
			return;
			if (this.mBindState == 2) {
				innerUnbindLocationAgentService(paramBoolean);
				continue;
			}
			if (this.mBindState != 0)
				continue;
			Log.d("PostcardActivity",
					"LocationAgentService is not bind. but user call unbind");
		}
	}

	private void updateAccuracyToIndicator() {
		if (this.mFootprint.mAccuracy == 0)
			this.mIndicator.setImageLevel(6);
		while (true) {
			return;
			if (this.mFootprint.mAccuracy == 2) {
				this.mIndicator.setImageLevel(5);
				continue;
			}
			if (this.mFootprint.mAccuracy != 3)
				continue;
			this.mIndicator.setImageLevel(5);
		}
	}

	private void updateToFootprint() {
		if (this.mFixLocation != null) {
			this.mFootprint.setAccuracyByProvider(this.mFixLocation
					.getProvider());
			this.mFootprint.mLatitude = (int) (1000000.0D * this.mFixLocation
					.getLatitude());
			this.mFootprint.mLongitude = (int) (1000000.0D * this.mFixLocation
					.getLongitude());
		}
	}

	public Footprint createFootprint(String paramString) {
		Footprint localFootprint1 = new Footprint();
		if (paramString != null)
			;
		Footprint localFootprint2;
		try {
			if (paramString.length() > 10)
				localFootprint1.setPic(paramString);
			while (true) {
				localFootprint1.setAudio("");
				localFootprint1.mName = FootprintUtils
						.getDefaultName(getApplicationContext());
				localFootprint1.mCreateTime = System.currentTimeMillis();
				localFootprint1.mCategory = this.mSelectedCateoryStr;
				if ((this.mFixLocation == null)
						|| (this.mFixLocation.getProvider() == null))
					break;
				localFootprint1.mLatitude = (int) Math
						.round(1000000.0D * this.mFixLocation.getLatitude());
				localFootprint1.mLongitude = (int) Math
						.round(1000000.0D * this.mFixLocation.getLongitude());
				localFootprint1.setAccuracyByProvider(this.mFixLocation
						.getProvider());
				break;
				localFootprint1.setPic("");
			}
		} catch (Exception localException) {
			Log.e("PostcardActivity", "saveFootprint exception", localException);
			localFootprint2 = null;
			break label158;
			localFootprint2 = localFootprint1;
		}
		label158: return localFootprint2;
	}

	void initView() {
		this.mPostCardPreview = ((ImageView) findViewById(postcard_preview));
		this.mFootprintTitle = ((TextView) findViewById(2131493009));
		this.mFootprintAddDate = ((TextView) findViewById(2131493010));
		this.buttonDone = findViewById(2131492964);
		this.buttonPlay = ((PlayButton) findViewById(2131493011));
		this.buttonPlay.setfootprintData(this.mFootprint);
		if (FootprintUtils.checkAudioData(this.mFootprint))
			this.buttonPlay.setVisibility(0);
		while (true) {
			this.mPostCardPreview.setOnClickListener(this);
			this.buttonDone.setOnClickListener(this);
			this.needAnimation = true;
			return;
			this.buttonPlay.setVisibility(4);
		}
	}

	protected void onActivityResult(int paramInt1, int paramInt2, Intent paramIntent)
  {
    Log.i("PostcardActivity", "onActivityResult, requestCode = " + paramInt1);
    if (paramInt1 == 1)
      this.isPickerRunning = false;
    label330: 
    do
    {
      do
      {
        try
        {
          if (this.gpsEnabled)
            this.mService.setTimeoutNotify(true);
          if (paramInt2 != -1);
        }
        catch (RemoteException localRemoteException1)
        {
          while (true)
          {
            try
            {
              if ((!this.gpsEnabled) || (!this.mService.isTracking()))
                continue;
              Log.i("PostcardActivity", "mService ");
              this.mService.stopTracking();
              double d1 = paramIntent.getDoubleExtra("RETURN_LATITUDE", 0.0D);
              double d2 = paramIntent.getDoubleExtra("RETURN_LONGITUDE", 0.0D);
              Location localLocation2 = new Location("map");
              localLocation2.setTime(System.currentTimeMillis());
              localLocation2.setLatitude(d1);
              localLocation2.setLongitude(d2);
              this.mFixLocation = localLocation2;
              this.mIndicator.setVisibility(0);
              this.mHandler.sendEmptyMessageDelayed(54, 200L);
              Log.d("PostcardActivity", "onActivityResult call HANDLE_GEOCODER_BY_GPS");
              this.mHandler.sendEmptyMessage(52);
              return;
              localRemoteException1 = localRemoteException1;
              localRemoteException1.printStackTrace();
            }
            catch (RemoteException localRemoteException3)
            {
              localRemoteException3.printStackTrace();
              continue;
            }
            try
            {
              if ((this.gpsEnabled) && (this.mService.isTracking()))
                continue;
              this.mHandler.sendEmptyMessageDelayed(54, 500L);
            }
            catch (RemoteException localRemoteException2)
            {
              localRemoteException2.printStackTrace();
            }
          }
        }
        if (paramInt1 != 5555)
          break;
        this.isRecaptureRunning = false;
      }
      while (paramInt2 != -1);
      Location localLocation1 = (Location)paramIntent.getParcelableExtra("FIX_LOCATION");
      String str;
      if (localLocation1 != null)
      {
        if (this.mFixLocation == null)
        {
          this.mFixLocation = new Location("gps");
          this.mFixLocation.set(localLocation1);
          this.mHandler.sendEmptyMessageDelayed(54, 500L);
        }
      }
      else
      {
        str = paramIntent.getStringExtra("EXTRA_PHOTO_PATH");
        ImageView localImageView = this.mPostCardPreview;
        FootprintImageManager localFootprintImageManager = FootprintImageManager.getInstance();
        File localFile = new File(str);
        localImageView.setImageBitmap(localFootprintImageManager.getImage(localFile, getApplicationContext()));
        if ((str == null) || (str.length() <= 0))
          break label455;
        this.mFootprint.mPicPath = str;
      }
      for (this.mFootprint.mPicFileName = str.substring(11 + str.lastIndexOf("/")); ; this.mFootprint.mPicFileName = "")
      {
        this.needAnimation = true;
        break;
        this.mFixLocation.set(localLocation1);
        break label330;
        this.mFootprint.mPicPath = "";
      }
    }
    while (paramInt1 != 18);
    label455: if (paramInt2 == -1)
    {
      Log.i("PostcardActivity", "REQUEST_DETAIL_EDIT, RESULT_OK");
      this.mFootprint = ((Footprint)paramIntent.getParcelableExtra("DATA"));
      this.mFootprintTitle.setText(this.mFootprint.mName);
      this.buttonPlay.setfootprintData(this.mFootprint);
      if (FootprintUtils.checkAudioData(this.mFootprint))
      {
        this.buttonPlay.setVisibility(0);
        Bitmap localBitmap2 = FootprintImageManager.getInstance().getImage(new File(this.mFootprint.mPicPath), this);
        this.mPostCardPreview.setImageBitmap(localBitmap2);
        finish();
      }
    }
    label556: Footprint localFootprint;
    do
    {
      updateAccuracyToIndicator();
      break;
      this.buttonPlay.setVisibility(4);
      break label556;
      localFootprint = (Footprint)paramIntent.getParcelableExtra("DATA");
    }
    while (localFootprint == null);
    this.mFootprint = localFootprint;
    this.mFootprintTitle.setText(this.mFootprint.mName);
    this.buttonPlay.setfootprintData(this.mFootprint);
    if (FootprintUtils.checkAudioData(this.mFootprint))
      this.buttonPlay.setVisibility(0);
    while (true)
    {
      Bitmap localBitmap1 = FootprintImageManager.getInstance().getImage(new File(this.mFootprint.mPicPath), this);
      this.mPostCardPreview.setImageBitmap(localBitmap1);
      break;
      this.buttonPlay.setVisibility(4);
    }
  }

	public void onClick(View paramView) {
		if (!paramView.isEnabled())
			;
		while (true) {
			return;
			if (paramView != this.buttonDone)
				continue;
			updateToFootprint();
			FootprintUtils.setLocationToPicture(this.mFootprint);
			FootprintUtils.forceSync(getContentResolver(),
					this.mFootprint.mPicFileName);
			saveFootprint(this);
			try {
				if ((this.gpsEnabled) && (this.mService != null))
					this.mService.stopTrackingWithoutNotify();
				if (this.isLanuchByWidget) {
					Log.d("PostcardActivity", "LanuchByWidget");
					FootprintUtils.setWidgetFlag();
				}
				finish();
			} catch (RemoteException localRemoteException) {
				while (true)
					localRemoteException.printStackTrace();
			}
		}
	}

	protected void onCreate(Bundle paramBundle) {
		super.onCreate(paramBundle);
		Log.d("PostcardActivity", "onCreate, savedInstanceState = "
				+ paramBundle);
		setVolumeControlStream(3);
		requestWindowFeature(1);
		Intent localIntent = getIntent();
		this.mFixNetwork = ((Location) localIntent
				.getParcelableExtra("FIX_NETWORK"));
		Location localLocation = (Location) localIntent
				.getParcelableExtra("FIX_LOCATION");
		this.mFixLocation = localLocation;
		this.mSelectedCategory = ((Category) localIntent
				.getParcelableExtra("CATEGORY"));
		String str1;
		if (this.mSelectedCategory != null)
			if (this.mSelectedCategory.mKeyword.equalsIgnoreCase("")) {
				this.mSelectedCateoryStr = "favorite";
				this.mFootprint = createFootprint(localIntent
						.getStringExtra("EXTRA_PHOTO_PATH"));
				Log.i("PostcardActivity", "get category from parcel: "
						+ this.mSelectedCateoryStr);
				setContentView(R.layout.postcard);
				initView();
				java.text.DateFormat localDateFormat = android.text.format.DateFormat
						.getDateFormat(getApplicationContext());
				this.mFootprintAddDate.setText(localDateFormat.format(new Date(
						this.mFootprint.mCreateTime)));
				this.mPostCardPreview.setImageBitmap(FootprintImageManager
						.getInstance().getImage(
								new File(localIntent
										.getStringExtra("EXTRA_PHOTO_PATH")),
								getApplicationContext()));
				this.mIndicator = ((ImageView) findViewById(2131492952));
				this.mGpsText = ((TextView) findViewById(2131492953));
				DecimalFormat localDecimalFormat = new DecimalFormat(" ##000");
				str1 = localIntent.getStringExtra("TITLE_NAME");
				int i = SettingInfo.getInstance(this).getCurrentSerialNumber();
				if (str1 != null)
					break label647;
				String str5 = TitleGenerator.getInstance(this)
						.getTitleFromMccTable();
				if (str5 != null)
					this.mFootprint.mName = (str5 + localDecimalFormat
							.format(i));
				label357: this.mFootprintTitle.setText(this.mFootprint.mName);
				String str2 = localIntent.getStringExtra("ADDRESS");
				if (str2 != null)
					this.mFootprint.mAddr = str2;
				String str3 = localIntent.getStringExtra("PHONE");
				if (str3 != null)
					this.mFootprint.mTel = str3;
				String str4 = localIntent.getStringExtra("WEBSITE");
				if (str4 != null)
					this.mFootprint.mSite = str4;
				this.mStorageUtil = new StorageUtil(getApplicationContext());
				this.mStorageUtil
						.SetOnChangeStorageListerner(new StorageUtil.OnChangeStorageListener() {
							public void onStorageChanged(int paramInt) {
								if (paramInt > 1)
									PostcardActivity.this
											.startActivity(FootprintUtils
													.getResetIntent());
							}
						});
				this.gpsEnabled = ((LocationManager) getSystemService("location"))
						.isProviderEnabled("gps");
				if ((paramBundle == null) && (localLocation == null)) {
					if (!this.gpsEnabled)
						break label659;
					Log.d("PostcardActivity", "onCreate. call bind service");
					bindLocationAgentService();
					this.mHandler.sendEmptyMessage(50);
				}
				label529: if (this.mFixLocation == null)
					break label688;
				Log.d("PostcardActivity",
						"onCreate call HANDLE_UPDATE_INDICATOR");
				this.mHandler.sendEmptyMessageDelayed(54, 200L);
				Log.d("PostcardActivity",
						"onCreate call HANDLE_GEOCODER_BY_GPS");
				this.mHandler.sendEmptyMessageDelayed(52, 500L);
			}
		while (true) {
			this.isLanuchByWidget = localIntent.getBooleanExtra(
					"LAUNCH_BY_WIDGET", false);
			Log.d("PostcardActivity", "isLanuchByWidget = "
					+ this.isLanuchByWidget);
			return;
			this.mSelectedCateoryStr = this.mSelectedCategory.mKeyword;
			break;
			this.mSelectedCateoryStr = "favorite";
			break;
			label647: this.mFootprint.mName = str1;
			break label357;
			label659: this.mGpsText.setText(getResources()
					.getString(2131361812));
			this.mIndicator.setImageLevel(6);
			break label529;
			label688: if (this.mFixNetwork == null)
				continue;
			this.mHandler.sendEmptyMessageDelayed(53, 3000L);
		}
	}

	protected Dialog onCreateDialog(int paramInt) {
		Object localObject;
		switch (paramInt) {
		default:
			localObject = super.onCreateDialog(paramInt);
		case 0:
		case 1:
		case 2:
		case 3:
		case 4:
		}
		while (true) {
			return localObject;
			try {
				if (this.mService != null)
					this.mService.setTimeoutNotify(false);
				this.mListDialog = new HtcAlertDialog.Builder(this)
						.setTitle(2131361860)
						.setIcon(2130837677)
						.setItems(getResources().getStringArray(2131165186),
								new DialogInterface.OnClickListener() {
									public void onClick(
											DialogInterface paramDialogInterface,
											int paramInt) {
										switch (paramInt) {
										default:
										case 0:
										case 1:
										case 2:
										}
										while (true) {
											paramDialogInterface.dismiss();
											return;
											PostcardActivity.this.doFindOnMap();
											continue;
											try {
												PostcardActivity.this.mService
														.continueTracking();
												PostcardActivity.this.mService
														.setTimeoutNotify(true);
											} catch (RemoteException localRemoteException2) {
												localRemoteException2
														.printStackTrace();
											}
											continue;
											PostcardActivity.this.getWindow()
													.clearFlags(128);
											PostcardActivity.this.mGpsText
													.setText(PostcardActivity.this
															.getResources()
															.getString(
																	2131361810));
											try {
												PostcardActivity.this.mService
														.stopTracking();
												PostcardActivity.this.mService
														.setTimeoutNotify(true);
												PostcardActivity.this
														.updateToFootprint();
												PostcardActivity.this
														.updateAccuracyToIndicator();
											} catch (RemoteException localRemoteException1) {
												localRemoteException1
														.printStackTrace();
											}
										}
									}
								}).create();
				this.mListDialog.setOnKeyListener(this.dlgKeyListener);
				localObject = this.mListDialog;
			} catch (RemoteException localRemoteException) {
				while (true)
					localRemoteException.printStackTrace();
			}
			localObject = new HtcAlertDialog.Builder(this)
					.setTitle(getString(2131361812))
					.setIcon(17301543)
					.setMessage(getString(2131361941))
					.setPositiveButton(2131361949,
							new DialogInterface.OnClickListener() {
								public void onClick(
										DialogInterface paramDialogInterface,
										int paramInt) {
									PostcardActivity.access$1602(
											PostcardActivity.this, true);
									Intent localIntent = new Intent(
											"android.settings.LOCATION_SOURCE_SETTINGS");
									paramDialogInterface.dismiss();
									PostcardActivity.this
											.startActivity(localIntent);
								}
							}).setNegativeButton(2131361796, null).create();
			continue;
			localObject = new HtcAlertDialog.Builder(this)
					.setTitle(getString(2131361946)).setIcon(2130837677)
					.setMessage(getString(2131361948))
					.setPositiveButton(2131361893, null).create();
			continue;
			this.progressDialog = new ProgressDialog(this);
			this.progressDialog
					.setMessage(getResources().getString(2131361964));
			this.progressDialog.setIndeterminate(true);
			this.progressDialog.setCancelable(true);
			this.progressDialog.setOnKeyListener(this.dlgKeyListener);
			localObject = this.progressDialog;
			continue;
			localObject = new HtcDialog(this).getLocationPickerNotFoundDialog();
		}
	}

	public boolean onCreateOptionsMenu(Menu paramMenu) {
		paramMenu.add(0, 0, 0, getResources().getString(2131361864)).setIcon(
				2130837685);
		paramMenu.add(0, 1, 1, getResources().getString(2131361855)).setIcon(
				2130837681);
		paramMenu.add(0, 2, 2, getResources().getString(2131361863)).setIcon(
				2130837682);
		paramMenu.add(0, 3, 3, getResources().getString(2131361859)).setIcon(
				2130837684);
		paramMenu.add(0, 4, 4, getResources().getString(2131361808)).setIcon(
				2130837678);
		paramMenu.add(0, 5, 5, getResources().getString(2131361807)).setIcon(
				2130837679);
		this.mMenu = paramMenu;
		return true;
	}

	protected void onDestroy() {
		Log.d("PostcardActivity", "onDestroy");
		removeQueuedMessages();
		unbindLocationAgentService(false);
		super.onDestroy();
	}

	public boolean onKeyDown(int paramInt, KeyEvent paramKeyEvent) {
		if (paramInt == 4) {
			updateToFootprint();
			FootprintUtils.setLocationToPicture(this.mFootprint);
			saveFootprint(this);
			this.isRecaptureRunning = true;
			this.mHandler.sendEmptyMessageDelayed(57, 50L);
		}
		for (boolean bool = true;; bool = super.onKeyDown(paramInt,
				paramKeyEvent)) {
			return bool;
			if (((paramInt != 19) && (paramInt != 20) && (paramInt != 21) && (paramInt != 22))
					|| (this.buttonDone.isFocusable()))
				continue;
			this.buttonDone.setFocusable(true);
			this.buttonPlay.setFocusable(true);
		}
	}

	public boolean onOptionsItemSelected(MenuItem paramMenuItem) {
		getWindow().clearFlags(WindowManager.LayoutParams.ALPHA_CHANGED);
		int i = paramMenuItem.getItemId();
		if (i == 3) {
			this.isRecaptureRunning = true;
			Intent localIntent3 = new Intent(this, FootprintCamera.class);
			localIntent3.putExtra(footpoi, 2);
			localIntent3.putExtra("LAUNCH_BY_WIDGET", this.isLanuchByWidget);
			Log.d("PostcardActivity", "MENU_RE_CAPTURE, isLanuchByWidget = "
					+ this.isLanuchByWidget);
			startActivityForResult(localIntent3, 5555);
		}
		while (true) {
			return true;
			if (i == 2) {
				if (this.gpsEnabled) {
					getWindow().addFlags(128);
					try {
						this.mService.enableMyLocation();
						((TextView) findViewById(2131492953))
								.setText(getResources().getString(2131361809));
						paramMenuItem.setEnabled(false);
					} catch (RemoteException localRemoteException2) {
						while (true)
							localRemoteException2.printStackTrace();
					}
				}
				showDialog(1);
				continue;
			}
			if (i == 1)
				try {
					if (this.gpsEnabled)
						this.mService.setTimeoutNotify(false);
					localIntent2 = new Intent("com.htc.android.locationpicker");
					localIntent2.putExtra(
							"PickerIcon",
							((BitmapDrawable) getResources().getDrawable(
									2130837655)).getBitmap());
					localIntent2.putExtra("InputLocation", 3);
					localIntent2.putExtra("PickerMode", 1);
					localIntent2.putExtra("PickerPanelStyle", 8);
					localIntent2.putExtra("PickerReturnType", 9);
					if (this.mFixLocation == null)
						if (this.mFixNetwork != null) {
							localIntent2.putExtra("PickerLatitude",
									this.mFixNetwork.getLatitude());
							localIntent2.putExtra("PickerLongitude",
									this.mFixNetwork.getLongitude());
							localIntent2
									.putExtra(
											"PickerAlertConnectionFailed",
											SettingInfo.getInstance(this).showConnectionFailedAlert);
							try {
								this.isPickerRunning = true;
								startActivityForResult(localIntent2, 1);
							} catch (ActivityNotFoundException localActivityNotFoundException) {
								showDialog(4);
							}
						}
				} catch (RemoteException localRemoteException1) {
					while (true) {
						Intent localIntent2;
						localRemoteException1.printStackTrace();
						continue;
						localIntent2.putExtra("InputLocation", 4);
						continue;
						localIntent2.putExtra("PickerLatitude",
								this.mFixLocation.getLatitude());
						localIntent2.putExtra("PickerLongitude",
								this.mFixLocation.getLongitude());
					}
				}
			if (i == 0) {
				this.recordDialog = new AudioRecordDialog(this, this.mFootprint);
				this.recordDialog
						.setRecordStatusListener(new AudioRecordDialog.recordStateListener() {
							public void OnRecorded(int paramInt,
									Footprint paramFootprint) {
								if (paramInt == 1)
									new Handler().post(new Runnable(
											paramFootprint) {
										public void run() {
											if ((this.val$data.mAudioPath == null)
													|| (this.val$data.mAudioFileName
															.length() == 0))
												PostcardActivity.this.buttonPlay
														.setVisibility(4);
											while (true) {
												return;
												PostcardActivity.this.buttonPlay
														.setVisibility(0);
												PostcardActivity.this.buttonPlay
														.setfootprintData(this.val$data);
											}
										}
									});
							}
						});
				this.recordDialog.show();
				continue;
			}
			if (i == 5) {
				Intent localIntent1 = new Intent(
						"com.htc.android.footprints.activity.FootprintDetailEditActivity");
				try {
					saveFootprint(this);
					localIntent1.putExtra("DATA", this.mFootprint);
					startActivityForResult(localIntent1, 18);
				} catch (Exception localException) {
					Log.e("PostcardActivity", localException.getMessage(),
							localException);
				}
				continue;
			}
			if (i != 4)
				continue;
			new HtcAlertDialog.Builder(this)
					.setTitle(getString(2131361957))
					.setIcon(17301543)
					.setMessage(getString(2131361815))
					.setPositiveButton(getString(2131361893),
							new DialogInterface.OnClickListener() {
								public void onClick(
										DialogInterface paramDialogInterface,
										int paramInt) {
									paramDialogInterface.dismiss();
									if (PostcardActivity.this.mFootprint
											.getID() >= 0)
										FootprintManager
												.getInstance(
														PostcardActivity.this
																.getApplicationContext())
												.removeFootprint(
														PostcardActivity.this.mFootprint
																.getID());
									if (PostcardActivity.this.mService != null)
										;
									try {
										PostcardActivity.this.mService
												.stopTrackingWithoutNotify();
										PostcardActivity.this.finish();
										return;
									} catch (RemoteException localRemoteException) {
										while (true)
											localRemoteException
													.printStackTrace();
									}
								}
							})
					.setNegativeButton(getString(2131361796),
							new DialogInterface.OnClickListener() {
								public void onClick(
										DialogInterface paramDialogInterface,
										int paramInt) {
									paramDialogInterface.dismiss();
								}
							}).show();
		}
	}

	protected void onPause() {
		Log.i("PostcardActivity", "onPause");
		if ((this.recordDialog != null) && (this.recordDialog.isShowing())) {
			this.recordDialog.terminateRecording();
			this.recordDialog.dismiss();
		}
		this.mHandler.removeMessages(0);
		this.buttonPlay.stopPlayback();
		ViewSwitcher localViewSwitcher = (ViewSwitcher) findViewById(2131492939);
		localViewSwitcher.setVisibility(8);
		localViewSwitcher.showPrevious();
		this.needAnimation = true;
		if ((this.mService != null) && (!this.isPickerRunning)
				&& (!this.isRecaptureRunning))
			;
		try {
			this.mService.waitForPause();
			if (this.mStorageUtil != null)
				this.mStorageUtil.closeStorgaeUtil();
			TitleGenerator.getInstance(this).stopTitleSearch();
			super.onPause();
			return;
		} catch (RemoteException localRemoteException) {
			while (true)
				localRemoteException.printStackTrace();
		}
	}

	public boolean onPrepareOptionsMenu(Menu paramMenu) {
		boolean bool1 = true;
		if (this.gpsEnabled)
			;
		try {
			boolean bool2 = this.mService.isTracking();
			if (!bool2)
				;
			for (bool1 = true;; bool1 = false) {
				paramMenu.findItem(2).setEnabled(bool1);
				return true;
			}
		} catch (RemoteException localRemoteException) {
			while (true)
				localRemoteException.printStackTrace();
		}
	}

	protected void onRestoreInstanceState(Bundle paramBundle) {
		Log.e("PostcardActivity", "onRestoreInstanceState");
		this.mFootprint = ((Footprint) paramBundle.getParcelable("DATA"));
		paramBundle.remove("android:savedDialogs");
	}

	protected void onResume() {
		super.onResume();
		Log.i("PostcardActivity", "onResume");
		if (this.needAnimation)
			showAnimation();
		this.gpsEnabled = ((LocationManager) getSystemService("location"))
				.isProviderEnabled("gps");
		if (!this.gpsEnabled)
			this.refreshRequired = false;
		if (this.mService != null)
			;
		while (true) {
			try {
				Log.d("PostcardActivity", "mService.resume() at onResume");
				this.mService.resume();
				if (!this.mService.isTimeout())
					continue;
				this.mHandler.sendEmptyMessageDelayed(50, 100L);
				if (this.mStorageUtil == null)
					continue;
				this.mStorageUtil.startStorageUtil();
				return;
			} catch (RemoteException localRemoteException) {
				localRemoteException.printStackTrace();
				continue;
			}
			if ((this.mBindState != 0) || (!this.gpsEnabled))
				continue;
			bindLocationAgentService();
		}
	}

	protected void onSaveInstanceState(Bundle paramBundle) {
		Log.e("PostcardActivity", "onSaveInstanceState");
		paramBundle.putParcelable("DATA", this.mFootprint);
	}

	protected void onStart() {
		super.onStart();
	}

	protected void onStop() {
		Log.i("PostcardActivity", "onStop");
		super.onStop();
	}

	public boolean saveFootprint(Context paramContext) {
		if (this.mFootprint != null) {
			int j = FootprintManager.getInstance(getApplicationContext())
					.addFootprint(this.mFootprint);
			if (j >= 0)
				this.mFootprint.setID(j);
		}
		for (int i = 1;; i = 0)
			return i;
	}
}

/*
 * Location:
 * E:\workspace\dex2java\dex-translator-0.0.9.3\HtcFootprints_dex2jar.jar
 * Qualified Name: com.htc.android.footprints.activity.PostcardActivity JD-Core
 * Version: 0.6.0
 */